<template>
	<view class="box">
		<view class="boxup">
			<image src="@/static/image/pjt.png">
			</image>
			<view class="flex-col zhanghu items-center flex justify-center">
				<view class="money">{{ money }}</view>
				<view class="balance">账户余额</view>
				<view class="payouts" @click="handleClick">提现</view>
			</view>
		</view>
		<z-paging ref="paging" :fixed="false" use-page-scroll v-model="dataList" @query="queryList">
			<view class="list" v-if="dataList && dataList.length>0">
				<view class="item" v-for="(item, index) in dataList" :key="index">
					<view class="top">
						<view class="left">
							<view class="text">
								{{ item.desc }}
							</view>
						</view>
						<view class="money">{{ item.money }}</view>
					</view>
					<view class="bottom">
						<view class="">{{ item.create_time }}</view>
						<view class="">
							余额{{ item.after_money }}
						</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script setup>
	import {
		ref,
	} from 'vue'
	import user from '@/api/user.js'
	// 必须导入需要用到的页面生命周期（即使在当前页面上没有直接使用到）
	import {
		onPageScroll,
		onReachBottom
	} from '@dcloudio/uni-app';
	import useZPaging from "@/uni_modules/z-paging/components/z-paging/js/hooks/useZPaging.js";
	const dataList = ref([])
	const paging = ref()
	const money = uni.getStorageSync('userInfo')?.money
	// 类似mixins，如果是页面滚动务必要写这一行，并传入当前ref绑定的paging，注意此处是paging，而非paging.value
	useZPaging(paging)
	const queryList = async (pageNo, pageSize) => {
		const { status, info, data } = await user.moneyLog({
			page: pageNo,
			page_size: pageSize
		})
		if(status == 1) {
			paging.value.complete(data.list)
		};
	}
	const handleClick = () => {
		uni.navigateTo({
			url: '/pages/user/withdraw_deposit'
		})
	}
</script>

<style scoped lang="scss">
	.box {
		padding: 24rpx;

		.boxup {
			position: relative;
			height: 308rpx;
			margin-bottom: 10rpx;

			image {
				position: absolute;
				left: -24rpx;
				width: calc(100% + 48rpx);
				height: 100%;
			}

			.zhanghu {
				position: inherit;

				.money {
					margin: 20rpx 0;
					font-family: Alibaba PuHuiTi 3.0, Alibaba PuHuiTi 30;
					font-weight: 600;
					font-size: 54rpx;
					color: #FFFFFF;
					line-height: 76rpx;
				}

				.balance {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #FFFFFF;
					line-height: 39rpx;
				}

				.payouts {
					width: 220rpx;
					height: 68rpx;
					display: flex;
					border-radius: 8rpx;
					margin-top: 40rpx;
					align-items: center;
					justify-content: center;
					background: #fff;
					border: 1px solid;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					font-size: 28rpx;
					color: #F1692B;
					line-height: 39rpx;
				}
			}
		}

		.boxunder {
			background: #FFFFFF;
			box-shadow: 0rpx 8rpx 16rpx 0rpx rgba(128, 128, 128, 0.06);
			border-radius: 32rpx;
			padding: 20rpx;
		}
	}

	.list {
		background: #FFFFFF;
		box-shadow: 0rpx 8rpx 16rpx 0rpx rgba(128, 128, 128, 0.06);
		border-radius: 32rpx;
		padding: 20rpx;
		margin-top: 10rpx;

		.item {
			border-bottom: 1px solid #F6F6F6;
			padding-bottom: 24rpx;
			margin-bottom: 24rpx;

			.top {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.left {
					display: flex;
					align-items: center;

					.text {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #2C1F21;
						line-height: 39rpx;
					}

					.type {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #F1692B;
						margin-left: 20rpx;
					}
				}

				.money {
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					font-size: 28rpx;
					color: #2C1F21;
					line-height: 39rpx;
				}
			}

			.bottom {
				margin-top: 10rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #A6A1A1;
				line-height: 34rpx;
			}
		}
		.item:last-child {
			border: 0;
			margin: 0;
			padding: 0;
		}
	}
</style>